import org.newdawn.slick.*;
import java.util.ArrayList;

/**
 * Manages the different layers that could appear ingame.
 * Layers are exactly as they sound, they're layered to give the game a dynamic appearance.
 * For example, the menu is layered above the game, so when it's opened, it appears above the game.
 * 
 * @author Gerrit Jamerson, CodeMonkeys
 * @version 4/3/13
 */
public class LayerController
{
    private static InGameMenuLayer inGameMenuLayer;
    private static GameLayer gameLayer;

    private static ArrayList<ILayer> layerList;
    private static ArrayList<ILayer> layerStack;

    /**
     * Initializes the LayerController.
     */
    public static void initialize(IGamemode _gameMode)
    {
        layerList = new ArrayList<ILayer>();
        layerStack = new ArrayList<ILayer>();
        
        inGameMenuLayer = new InGameMenuLayer();
        gameLayer = new GameLayer(_gameMode);

        layerList.add(inGameMenuLayer);
        layerList.add(gameLayer);
        
        layerStack.add(gameLayer);
    } //End initialize method

    /**
     * Called every step, draws each layer in correct order.
     * 
     * @pre None
     * @param None
     * @return Void
     * @post Each layer has been updated one step
     */
    public static void update(GameContainer gameContainer, int intDelta)
    {
        for(ILayer layer : layerList)
        {
            layer.update(gameContainer, intDelta);
        } //End for loop
    } //End update method

    /**
     * Called every frame, draws each layer in correct order.
     * 
     * @pre None
     * @param gameContainer The game container
     * @param graphics The graphics class
     * @return Void
     * @post Layers are drawn to the screen
     */
    public static void render(GameContainer gameContainer, Graphics graphics)
    {
        for(ILayer layer : layerList)
        {
            layer.render(gameContainer, graphics);
        } //End for loop
    } //End render method

    /**
     * Called when a key is pressed.
     * 
     * @pre None
     * @param key The key that was pressed.
     * @return void
     * @post None
     */
    public static void keyPressed(Keys key)
    {
        layerStack.get(layerStack.size() - 1).keyPressed(key);
    } //End keyPress method

    /**
     * Called when a key is pressed.
     * 
     * @pre None
     * @param key The key that was released.
     * @return void
     * @post None
     */
    public static void keyReleased(Keys key)
    {
        layerStack.get(layerStack.size() - 1).keyReleased(key);
    } //End keyRelease method
} //End class
